# Contributor: Michael Pirogov <vbnet.ru@gmail.com>
# Maintainer: Michael Pirogov <vbnet.ru@gmail.com>
pkgname=janus-gateway
pkgver=1.2.1
pkgrel=0
pkgdesc="Janus WebRTC Server"
url="https://janus.conf.meetecho.com/"
license="GPL-3.0-only"
arch="all"
install="$pkgname.pre-install"
makedepends="
	autoconf
	automake
	cmake
	curl-dev
	doxygen
	duktape-dev
	ffmpeg-dev
	gengetopt
	graphviz
	jansson-dev
	libconfig-dev
	libmicrohttpd-dev
	libnice-dev
	libogg-dev
	libogg-dev
	libopusenc-dev
	libsrtp-dev
	libtool
	libusrsctp-dev
	libuv-dev
	libwebsockets-dev
	lua
	lua5.3-dev
	npm
	paho-mqtt-c-dev
	rabbitmq-c-dev
	sofia-sip-dev
	zlib-dev
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/meetecho/janus-gateway/archive/refs/tags/v$pkgver.tar.gz
	$pkgname.initd
	$pkgname.confd
	"
subpackages="$pkgname-doc $pkgname-openrc"
options="!check" # missing aiortc

# nanomsg not available on armv7
case "$CARCH" in
	arm*)
		;;
	*)
		makedepends="$makedepends nanomsg-dev"
		;;
esac

prepare() {
	default_prepare
	autoreconf -fi

	cd npm
	npm ci
}

build() {
	cd npm
	npm run prerelease
	cd ..

	./configure \
		--prefix=/usr \
		--sysconfdir=/etc \
		--runstatedir=/run \
		--enable-sample-event-handler \
		--enable-rest \
		--enable-javascript-es-module \
		--enable-post-processing \
		--enable-json-logger \
		--enable-plugin-lua \
		--enable-plugin-sip \
		--enable-plugin-duktape \
		--enable-mqtt \
		--enable-docs \
		--disable-aes-gcm

	make
}

package() {
	make DESTDIR="$pkgdir" install
	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -Dm644 "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
}

sha512sums="
164ccbcac5460dfaaf43571e0d13f2015e76937a3888421e5ec6d7a9c1d89c73a108acb4a748b0e9940494f0847f7c4c73e29250d45693cf6d07e104f78aab96  janus-gateway-1.2.1.tar.gz
7c6f530c93340c326b603198cb17ed1fdeb32d0e257e54f21a0ffe0643fd97696337ddf270c33111d01bc1d29ebe9f622988f26510a714a2db783faff8be8337  janus-gateway.initd
f442a419a435f5d1adab673011b7689a5680064f32f712e5e4668c486ce10f1442822c60cb302ee850ddc576a9e9f610a0863f02204e56f1fc68aa3ee312ebe0  janus-gateway.confd
"
